﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ConceptCorporateClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            treeView1.Enabled = false;
            toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    TreeNode nod = null;
                    this.Invoke(new MethodInvoker(delegate()
                        {
                            
                            nod = treeView1.Nodes.Add("test");
                            Application.DoEvents();
                            
                        }
                    ));

                    while (nod == null)
                        Application.DoEvents();

                    for (int j = 0; j < 10000; j++)
                    {
                        object obj = this.Invoke(new MethodInvoker(delegate()
                           {
                               nod.Nodes.Add("test copil");
                               Application.DoEvents();
                               
                           }
                        ));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + ex.StackTrace);
                    e.Cancel = true;
                }
            }
            this.Invoke(new MethodInvoker(
                delegate()
                {
                   toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
                   treeView1.Enabled = true;
                }));
            
        }

    }
}
